/*
* Copyright 2010 Competentum group
*
* Licensed under the GNU General Public License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.gnu.org/licenses/gpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.competentum.vos
{
	public class BindVO extends AbstractItemVO
	{
		public static const FORMAT:String = "bind";
		
		private var _project:AbstractItemVO;
		[Bindable]
		public function get project():AbstractItemVO
		{
			return _project;
		}
		public function set project(value:AbstractItemVO):void
		{
			if (_project != value)
			{
				var oldProject:AbstractItemVO = _project;
				_project = value;
				if (oldProject)
					oldProject.notifyHolders();
				_project.notifyHolders();
			}
		}
		
		private var _employee:AbstractItemVO;
		[Bindable]
		public function get employee():AbstractItemVO
		{
			return _employee;
		}
		public function set employee(value:AbstractItemVO):void
		{
			if (_employee != value)
			{
				var oldEmployee:AbstractItemVO = _project;
				_employee = value;
				if (oldEmployee)
					oldEmployee.notifyHolders();
				_employee.notifyHolders();
			}
		}
		
		[Bindable]
		private var _hoursReserved:Number = 0;
		public function set hoursReserved(value:Number):void
		{
			if ( _hoursReserved != value ) {
				_hoursReserved = value;
				notifyHolders();
				if ( employee ) {
					employee.notifyHolders();
				}
				if ( project ) {
					project.notifyHolders();
				}
			}
		}
		[Bindable]
		public function get hoursReserved():Number
		{
			return _hoursReserved;
		}
		
		public function BindVO()
		{
			super();
		}
		
		override public function exportToXML() : XML
		{
			var xml:XML = 
				<bind>
				</bind>;
			xml.@toEmployee = employee.uid;
			xml.@toProject = project.uid;
			xml.@hoursReserved = hoursReserved;
			return xml;
		}
		
		override public function notifyHolders():void
		{
			if (employee)
			{
				employee.notifyHolders();
			}
			if (project)
			{
				project.notifyHolders();
			}
			super.notifyHolders();
		}
		
		public function toString():String
		{
			return '(BindVO: ' + employee.uid + ', ' + project.uid + ', ' + hoursReserved + ')';
		}
	}
}